<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索</el-button
        >
      </el-col>
      <!--      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" :disabled="type1" @click="handleDelivery" v-hasPermi="['output:pickingPost:OneClickDelivery']">
          一键出库
        </el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-circle-check"
          size="mini"
          :disabled="type1"
          @click="handlePost()"
          v-hasPermi="['putSorage:pmmMstr:pmmPost']"
        >
          过账
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          :disabled="pickingList.length <= 0"
          icon="el-icon-circle-close"
          size="mini"
          @click="show"
          v-hasPermi="['putSorage:pmmMstr:rollback']"
        >
          撤回
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleDc('#exportGzDj', '生产退料单据')"
          v-hasPermi="['putSorage:pmmMstr:export']"
        >
          EXCEL
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleDc('#exportGzMx', '生产退料明细')"
          v-hasPermi="['putSorage:pmmMstr:export']"
        >
          退料明细
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleDc('#exportGzTj', '生产退料统计')"
          v-hasPermi="['putSorage:pmmMstr:export']"
        >
          退料统计
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#bb0331">通过</Tag>
      <Tag type="dot" size="default" color="#0323af">检验</Tag>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :data="pickingList"
      :cell-style="iCellStyle"
      :height="tableH"
      id="exportGzDj"
      @row-click="clickRow"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" type="index" width="40" align="center" />
      <el-table-column
        label="退料单号"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="pmmDjbh"
      />
      <el-table-column
        label="退料日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="pmmLlrq"
        width="180"
      />
      <!--      <el-table-column label="单据类型" :show-overflow-tooltip="true" width="100" align="center" prop="pmmType">
        <template #default="scope">
          <dict-tag :options="pmmTypeOptions" :value="scope.row.pmmType" />
        </template>
      </el-table-column>-->
      <el-table-column
        label="仓库代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.pmmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="退料部门"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmBmdm"
      />
      <el-table-column
        label="单据描述"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmDesc"
      />
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="pmmJlrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.pmmJlrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmShry"
      />
      <el-table-column
        label="审核日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="pmmShrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.pmmShrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="pmmGzrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.pmmGzrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="原因代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmYydm"
      >
        <template #default="scope">
          <dict-tag :options="pmmYydmOptions" :value="scope.row.pmmYydm" />
        </template>
      </el-table-column>
      <el-table-column
        label="原因描述"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="pmmYyms"
      />
      <el-table-column
        label="操作"
        align="center"
        width="100"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDjDy(scope.row)"
            v-hasPermi="['output:pickingPost:pmmPrint']"
            >单据打印</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!--明细-->
    <el-tabs v-model="activeTab">
      <el-tab-pane label="退料明细" name="first">
        <el-table
          border
          stripe
          id="exportGzMx"
          :height="tableHAddChild"
          :cell-style="iCellStyle2"
          :data="chdDetList"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column
            label="#"
            type="index"
            min-width="5"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="客户编码"
            align="center"
            min-width="20"
            prop="itmCustwldm"
            fixed="left"
          />
          <el-table-column
            label="制造单号"
            align="center"
            min-width="20"
            prop="pmdZzdh"
            fixed="left"
          />
          <el-table-column
            label="退料物料代码"
            align="center"
            min-width="20"
            prop="pmdWldm"
          />
          <el-table-column
            label="客户物料编码"
            align="center"
            min-width="20"
            prop="itmCustwldm"
          />
          <el-table-column
            label="规格描述"
            show-overflow-tooltip
            min-width="50"
            prop="itmPmgg"
          />
          <el-table-column
            label="申请数量"
            align="center"
            min-width="10"
            prop="pmdSqsl"
          />
          <el-table-column
            label="入库数量"
            align="center"
            min-width="10"
            prop="pmdCksl"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="存放位置"
            :show-overflow-tooltip="true"
            min-width="15"
            align="center"
            prop="pmdCwdm"
          >
            <template #default="scope">
              <dict-tag :options="allCwOptions" :value="scope.row.pmdCwdm" />
            </template>
          </el-table-column>
          <!--          <el-table-column label="入库人员" align="center" min-width="10" prop="pmdCkry" />
          <el-table-column label="入库日期" :show-overflow-tooltip="true" align="center" prop="pmdCkrq" min-width="24">
            <template #default="scope">
              <span>{{ parseTime(scope.row.pmdCkrq, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
            </template>
          </el-table-column>-->
          <el-table-column
            label="最小包装"
            align="center"
            min-width="10"
            prop="pmdMinbz"
          />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="退料统计" name="second">
        <el-table
          border
          stripe
          id="exportGzTj"
          :height="tableHAddChild"
          :data="chdDetTotalList"
          :cell-style="iCellStyle2"
        >
          <el-table-column label="#" type="index" align="center" fixed="left" />
          <el-table-column
            label="客户编码"
            align="center"
            prop="itmCustwldm"
            width="180"
            fixed="left"
          />
          <el-table-column
            label="物料代码"
            align="center"
            prop="pmdWldm"
            fixed="left"
            width="180"
          />
          <el-table-column label="规格描述" align="center" prop="itmPmgg" />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            align="center"
            prop="itmDw"
            width="80"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <!-- <el-table-column label="存放位置" :show-overflow-tooltip="true" align="center" prop="pmdCwdm">
            <template #default="scope">
              <dict-tag :options="allCwOptions" :value="scope.row.pmdCwdm" />
            </template>
          </el-table-column> -->
          <el-table-column
            label="最小包装"
            align="center"
            prop="pmdMinbz"
            width="80"
          />
          <el-table-column
            label="申请数量"
            align="center"
            prop="pmdSqsl"
            width="80"
          />
          <el-table-column
            label="入库数量"
            align="center"
            prop="pmdCksl"
            width="80"
          />
          <!--          <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
            <template #default="scope">
              <el-button
                size="mini"
                type="text"
                :disabled="type1"
                @click="handleCkqr(scope.row)"
                v-hasPermi="['output:pickingPost:outboundConfirmation']">
                出库确认
              </el-button>
            </template>
          </el-table-column>-->
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="450px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-col :span="24">
          <el-form-item label="退料单号" prop="pmmDjbh">
            <el-input
              v-model="queryParams.pmmDjbh"
              placeholder="请输入单据编号"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="退料日期">
            <el-date-picker
              v-model="daterangepmmLlrq"
              size="small"
              :clearable="false"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="仓库" prop="pmmCkdm">
            <el-select v-model="queryParams.pmmCkdm" placeholder="请选择仓库">
              <el-option
                v-for="item in storageOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <!--        <el-col :span="24">
          <el-form-item label="品名规格" prop="pmmPmgg">
            <el-input v-model="queryParams.pmmPmgg" clearable style="width: 240px" size="small" @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>-->
        <el-col :span="24">
          <el-form-item label="状态标志">
            <el-radio-group v-model="queryParams.pmmZtbz">
              <el-radio
                v-for="dict in cjmZtbzOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
                >{{ dict.dictLabel }}</el-radio
              >
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <!-- 出库确认对话框   -->
    <el-dialog
      :title="title"
      v-model="resultOpen"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form
        ref="pmdForm"
        :model="pmdForm"
        label-width="88px"
        :rules="pmdFormRules"
      >
        <el-col :span="24">
          <el-form-item label="退料单号" prop="pmdDjbh">
            <el-input v-model="pmdForm.pmdDjbh" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="pmdWldm">
            <el-input v-model="pmdForm.pmdWldm" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="品名规格" prop="itmPmgg">
            <el-input v-model="pmdForm.itmPmgg" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请数量" prop="pmdSqsl">
            <el-input v-model="pmdForm.pmdSqsl" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="存放位置" prop="pmdCwdm">
            <el-select
              v-model="pmdForm.pmdCwdm"
              placeholder="请选择入库类型"
              disabled
            >
              <el-option
                v-for="dict in allCwOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最小包装" prop="pmdMinbz">
            <el-input v-model="pmdForm.pmdMinbz" readonly />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库数量" prop="pmdCksl">
            <el-input v-model="pmdForm.pmdCksl" type="number" readonly />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ckSubmit">确 定</el-button>
        <el-button @click="resultOpen = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 撤回 -->
    <Modal v-model="check_back" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认撤回重写？</span>
      </p>
      <div style="text-align: center">
        <p>撤回理由</p>
        <Input v-model="back_reason" style="width: 75%" />
      </div>
      <div slot="footer">
        <Button type="error" size="large" long @click="handleBack">撤回</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  confirmScCk,
  exportPicking,
  oneClickDeliveryCk,
} from "@/api/output/picking";
import { getAll, getstorageType } from "@/api/repertory/Storage";
import { getAllCgList } from "@/api/project/mstr";
import { exportTable, printOrder } from "@/utils/ruoyi";
import {
  listPmmMstr,
  selectPmmMstrDetailAndTotalByOrder,
  updatePmmMstrState,
} from "@/api/putStorage/pmmMstr";

export default {
  name: "PmmPost",
  data() {
    return {
      // 遮罩层
      loading: true,
      openFull: false,
      // 导出遮罩层
      exportLoading: false,
      resultOpen: false,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      // 出库退料开单作业表格数据
      pickingList: [],
      cjmZtbzOptions: [],
      chdDetList: [],
      chdDetTotalList: [],
      serachAddList: [],
      tableH: 250,
      tableHChild: 300,
      tableHAdd: 250,
      tableHAddChild: 300,
      activeTab: "second",
      //所有仓库
      allStorageOptions: [],
      //有效仓库
      storageOptions: [],
      rowdata: [],
      //当前数据
      rowData: null,
      back_reason: null,
      djbh: null,
      //选择标识
      type1: true,
      check_back: false,
      //原因描述flag
      reasonDescriptionFlag: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 单据类型字典
      pmmTypeOptions: [],
      allCwOptions: [],
      // 原因代码字典
      pmmYydmOptions: [],
      itCarOptions: [],
      // 退料日期时间范围
      daterangepmmLlrq: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],
      unitFlagOptions: [],
      bomCgsxOptions: [],
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      pmdFormRules: {
        pmdCksl: [
          { required: true, message: "请输入入库数量", trigger: "blur" },
        ],
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 25,
        pmmDjbh: null,
        pmmLlrq: null,
        pmmCkdm: null,
        pmmPmgg: null,
        pmmZtbz: "2",
        pmmTjflag: "1",
      },
      // 添加物料-查询参数
      queryChildParams: {
        pageNum: 1,
        pageSize: 20,
        pmmZzdh: null,
        pmmCj: "所有",
        integratedQuery: null,
        pmmDjbh: null,
        pmmCkdm: null,
        pmmType: null,
      },
      // 表单参数
      form: {},
      pmdForm: {},
      // 表单校验
      rules: {
        pmmCkdm: [
          { required: true, message: "仓库代码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    //制造车间字典
    //单位
    this.getAllDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    this.getDicts("sys_post_ztbz").then((response) => {
      this.cjmZtbzOptions = response.data;
    });
    getAll().then((response) => {
      this.allCwOptions = response.data;

      for (let item2 of this.allCwOptions) {
        item2.dictLabel = item2.storageDefaultstorage;

        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });
    //得到采购属性
    getAllCgList().then((response) => {
      this.bomCgsxOptions = response.data;
      for (let i of this.bomCgsxOptions) {
        i.dictLabel = i.cgName;
        i.dictValue = i.cgId + "";
        i.listClass = "default";
      }
    });
    this.getDicts("Manufacturing_plant").then((response) => {
      this.itCarOptions = response.data;
    });
    this.getDicts("production_pick_type").then((response) => {
      this.pmmTypeOptions = response.data;
    });
    this.getDicts("reason_category").then((response) => {
      this.pmmYydmOptions = response.data;
    });
    //所有仓库
    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
    //有效仓库
    getstorageType("0").then((response) => {
      this.storageOptions = response.data;

      for (let item of this.storageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
  },
  methods: {
    iCellStyle2: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.pmdCksl) {
        return "color:#bb0331";
      }
    },
    ckSubmit() {
      confirmScCk(this.pmdForm.pmdDjbh, this.pmdForm.pmdWldm).then(
        (response) => {
          this.resultOpen = false;
          this.getChdDetList(this.pmdForm.pmdDjbh);
        }
      );
    },
    /** 查询出库退料开单作业列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangepmmLlrq && "" != this.daterangepmmLlrq) {
        this.queryParams.params["beginpmmLlrq"] = this.moment(
          this.daterangepmmLlrq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endpmmLlrq"] = this.moment(
          this.daterangepmmLlrq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.pageNum = 1;
      listPmmMstr(this.queryParams).then((response) => {
        this.pickingList = [];
        this.chdDetTotalList = [];
        this.chdDetList = [];
        this.pickingList = this.pickingList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRow(row);
        } else if (this.pickingList != null && this.pickingList.length > 0) {
          this.clickRow(this.pickingList[0]);
        }
      });
    },
    handleDjDy(row) {
      const data = { pmmDjbh: row.pmmDjbh };
      const pmmDjbh = row.pmmDjbh;
      if (row) {
        if (row.pmmZtbz !== "6") {
          this.$confirm("当前单据还未过账，是否过账并执行打印？", "温馨提醒", {
            confirmButtonText: "过账并打印",
            cancelButtonText: "取消",
            type: "info",
          }).then((res) => {
            if (pmmDjbh) {
              updatePmmMstrState(2, 6, pmmDjbh)
                .then((res) => {
                  this.msgSuccess("过账成功");
                  this.getList();
                  printOrder(
                    "/putStorage/pmmMstr/exportMaterialReturnTemplate",
                    data,
                    "计划退料单据"
                  );
                })
                .catch(() => {
                  this.msgError("过账失败");
                });
            } else {
              this.msgError("无过账单据");
            }
          });
          return;
        }
      }

      printOrder(
        "/putStorage/pmmMstr/exportMaterialReturnTemplate",
        data,
        "计划退料单据"
      );
    },
    /** 出库确认 */
    handleCkqr(row) {
      this.resetpmdForm();
      //开始赋值
      console.log(row);
      this.pmdForm.pmdWldm = row.pmdWldm;
      this.pmdForm.pmdDjbh = this.rowData.pmmDjbh;
      this.pmdForm.itmPmgg = row.itmPmgg;
      this.pmdForm.pmdSqsl = row.pmdSqsl;
      this.pmdForm.pmdCwdm = row.pmdCwdm;
      this.pmdForm.pmdMinbz = row.pmdMinbz;
      this.pmdForm.pmdCksl = this.pmdForm.pmdSqsl;
      this.title = "入库确认";
      this.resultOpen = true;
    },
    handleAdded(row) {
      this.openFull = true;
      this.queryChildParams.pmmDjbh = row.pmmDjbh;
      this.queryChildParams.pmmCkdm = row.pmmCkdm;
      this.queryChildParams.pmmType = row.pmmType;
    },
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.pmmZtbz == "1" && row.pmmTjflag == "1") {
        return "color:#0fac09";
      }
      //通过
      else if (row.pmmZtbz == "2" && row.pmmTjflag == "1") {
        return "color:#0323af";
      }
      //检验
      else if (row.pmmZtbz == "6" && row.pmmTjflag == "1") {
        return "color:#bb0331";
      }
    },
    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 25;
        this.queryParams.pageNum++;
        listPmmMstr(this.queryParams).then((response) => {
          this.pickingList = this.pickingList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    getChdDetList(chdDjbh) {
      selectPmmMstrDetailAndTotalByOrder(chdDjbh).then((response) => {
        this.chdDetTotalList = response.data.list2;
        this.chdDetList = response.data.list1;
      });
    },
    clickRow(row) {
      // //获得选中的详细数据
      this.rowData = row;
      // //获得当前单据的状态
      // this.ids = row.rwmId
      this.type1 = !(row != null && row.pmmZtbz == "2" && row.pmmTjflag == "1");
      //获得选中的详细数据
      this.getChdDetList(row.pmmDjbh);
    },
    // getpmdDetList(data) {
    //
    // },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pmmId: null,
        pmmDjbh: null,
        pmmType: null,
        pmmCkdm: null,
        pmmBmdm: null,
        pmmDesc: null,
        pmmTjflag: null,
        pmmNgdesc: null,
        pmmZtbz: null,
        pmmJlry: null,
        pmmJlrq: null,
        pmmShry: null,
        pmmShrq: null,
        pmmGzry: null,
        pmmGzrq: null,
        pmmYydm: null,
        pmmYyms: null,
        pmmLlrq: new Date(),
      };
      this.resetForm("form");
    },
    resetpmdForm() {
      this.pmdForm = {
        pmmDjbh: null,
        pmdWldm: null,
        itmPmgg: null,
        pmdSqsl: null,
        itmCwdm: null,
        pmdMinbz: null,
        pmdCksl: null,
      };

      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.pickingList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangepmmLlrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSearch() {
      this.reset();
      this.title = "查询入库退料开单作业";
      this.openSearch = true;
    },
    /**  一键过账 */
    handleDelivery() {
      if (this.chdDetList == null || this.chdDetList.length === 0) {
        this.msgError("该单据无明细");
      } else {
        this.$confirm("是否进行一键入库?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            oneClickDeliveryCk(this.rowData.pmmDjbh);
          })
          .then((response) => {
            this.msgSuccess("检验成功");
            this.getChdDetList(this.rowData.pmmDjbh);
          })
          .catch(() => {});
      }
    },
    /** 过账 */
    handlePost() {
      const cjmIds = this.rowData.pmmDjbh;
      if (cjmIds) {
        this.$confirm(
          '是否确认过账退料编号为"' + cjmIds + '"的数据项?',
          "警告",
          {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }
        )
          .then(function () {
            return updatePmmMstrState(2, 6, cjmIds);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("过账成功");
          })
          .catch(() => {});
      } else {
        this.msgError("无过账单据");
      }
    },
    show() {
      if (this.rowData.pmmZtbz === "2") {
        this.check_back = true;
      } else {
        this.$Modal.warning({
          title: "提示",
          content: "单据不是待过账状态，不允许此操作",
        });
      }
    },
    /** 撤回 */
    handleBack() {
      if (this.back_reason !== null && this.back_reason !== "") {
        updatePmmMstrState(2, 1, this.rowData.pmmDjbh, this.back_reason)
          .then((res) => {
            this.msgSuccess("撤回成功");
            this.check_back = false;
            this.getList();
          })
          .catch(() => {
            this.msgError("撤回失败");
          });
      } else {
        this.$Modal.warning({
          title: "提示",
          content: "撤回理由不能为空",
        });
      }
    },
    handleDc(a, b) {
      exportTable(a, b);
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有入库退料开单作业数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportPicking(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
